package com.system.patient.controller;

import com.system.patient.bean.Patient;
import com.system.patient.service.PatientService;
import com.system.patient.vo.PatientVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @className: PatientController
 * @description: TODO 类描述
 * @author: Li Chuanwei
 * @date: 2023/10/31 20:46
 * @Company: Copyright [日期] by [作者或个人]
 **/

@RestController
@RequestMapping("/patient")
public class PatientController {
    @Autowired
    private PatientService patientService;

    @PostMapping("/save")
    public boolean saveHandle(@RequestBody Patient patient){
        return patientService.savePatient(patient);
    }

    @DeleteMapping("/del/{id}")
    public boolean deleteHandle(@PathVariable("id") int id){
        return patientService.removePatientById(id);
    }

    @PutMapping("/update")
    public boolean updateHandle(@RequestBody Patient patient){
        return patientService.modifyPatient(patient);
    }

    @GetMapping("/get/{id}")
    public Patient getHandle(@PathVariable("id") int id){
        return patientService.getPatientById(id);
    }

    @GetMapping("/get/list")
    public List<Patient> listHandle(){
        return patientService.listAllPatients();
    }

    @GetMapping("/get/byLoginId/{loginId}")
    public List<Patient> getPatientsByLoginId(@PathVariable Integer loginId) {
        return patientService.getPatientsByLoginId(loginId);
    }

    @GetMapping("/get/name/{id}")
    public String getPatientName(@PathVariable("id") int id){
        return patientService.getPatientName(id);
    }

    @GetMapping("/get/patient/{id}")
    public PatientVo getPatientByIdCardNumber(@PathVariable("id") String id){
        return patientService.findByIdCardNumber(id);
    }

}
